package com.example.chinesenation.Utils;

import com.example.chinesenation.VO.MainPage.VOArticleList;

import javax.xml.crypto.Data;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author sakuraFallingDown
 * @version 1.0
 * @date 2021/3/3 14:47
 */
public class CommonFunction {
    public static Map<String,NationPopulation> sortHashMap(Map<String,NationPopulation> map){
        Map<String, NationPopulation> collect = map.entrySet().stream().sorted(new Comparator<Map.Entry<String, NationPopulation>>() {
            @Override
            public int compare(Map.Entry<String, NationPopulation> o1, Map.Entry<String, NationPopulation> o2) {
                return o1.getKey().compareTo(o2.getKey());
            }
        }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

        return collect;
    }

    public static String getRedisDayKey(int days){
        return getDateYearMonthDay(days)+":";
    }
    public static String getDateYearMonthDay(int days){//多少天前的年月日
        Calendar cd=Calendar.getInstance();
        cd.setTimeInMillis(System.currentTimeMillis()-days*24*60*60*1000);
        return ""+cd.get(Calendar.YEAR)+"-"+(cd.get(Calendar.MONTH)+1)+"-"+cd.get(Calendar.DAY_OF_MONTH);
    }
}
